package com.company.cloud.club.modules.db.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.company.cloud.club.modules.db.domain.ClubActivity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface ClubActivityMapper extends BaseMapper<ClubActivity> {

    @Select("SELECT * FROM club_activity WHERE deleted = 0 AND end_time > #{curr, jdbcType=BIGINT} AND hot = 1 ORDER BY sort DESC")
    List<ClubActivity> queryHot(@Param("curr") Long curr);

    @Select("SELECT * FROM club_activity WHERE deleted = 0 ORDER BY sort DESC")
    List<ClubActivity> queryAll();

    @Select("SELECT * FROM club_activity WHERE deleted = 0 AND end_time < #{curr, jdbcType=BIGINT} AND hot = 1")
    List<ClubActivity> queryHotHistory(@Param("curr") Long curr);

    @Update("UPDATE club_activity SET deleted = 1 WHERE id = #{id, jdbcType=VARCHAR}")
    boolean removeActivity(@Param("id") String id);

    @Select("SELECT * FROM club_activity " +
            "WHERE deleted = 0 AND location LIKE CONCAT('%', #{condition,jdbcType=VARCHAR}, '%') " +
            "OR title LIKE CONCAT('%', #{condition,jdbcType=VARCHAR}, '%') " +
            "OR label LIKE CONCAT('%', #{condition,jdbcType=VARCHAR}, '%') " +
            "OR intro LIKE CONCAT('%', #{condition,jdbcType=VARCHAR}, '%') " +
            "ORDER BY start_time DESC;")
    List<ClubActivity> selectByCondition(@Param("condition") String condition);

}